package com.fay.designPattern.pattern.behavior.observer;

import org.apache.logging.log4j.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title:
 * @Description:
 * @Author Fay Wang
 * @Date 2022/4/20 14:22
 * @Version 1.0
 */
public class ConcreteSubject implements Subject {

    private List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObserver(Message message) {
        for (Observer observer : observers) {
            observer.update(message);
        }
    }
}
